home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol05 / 06 / cpumeter / cpumet.c < prev    next >
C/C++ Source or Header  |  1990-11-01  |  3KB  |  108 lines

  1. //
  2. // cpumet.c - (c) 1990 Chiverton Graphics, Inc.
  3. //
  4.  
  5. #define INCL_WIN
  6. #define INCL_DOS
  7. #include <os2.h>
  8. #include <process.h>
  9. #include <stdio.h>
  10.  
  11. #define THREADSTACKSIZE   4096
  12.  
  13. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  14. VOID    TimerThread   (void) ;
  15. VOID    CounterThread (void) ;
  16.  
  17. TID   tidTimer ,
  18.       tidCounter;
  19.  
  20. HWND  hwndClient,
  21.       hwndFrame ;
  22.  
  23. HSYSSEM hSem ;
  24.  
  25. LONG  lCount = 0L;
  26.  
  27. INT   iTimerThreadStack     [THREADSTACKSIZE / 2] ,
  28.       iCounterThreadStack   [THREADSTACKSIZE / 2] ;
  29.  
  30. int main (void)
  31.      {
  32.      CHAR  szClientClass [] = "CPUMET";
  33.      ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_TASKLIST;
  34.      HAB   hab ;
  35.      HMQ   hmq ;
  36.      QMSG  qmsg ;
  37.  
  38.      if ( DosCreateSem(CSEM_PUBLIC, &hSem, "\\sem\\cpumeter.sem") )
  39.           DosExit (EXIT_PROCESS, 0);
  40.  
  41.      hab = WinInitialize (0) ;
  42.      hmq = WinCreateMsgQueue (hab, 0) ;
  43.  
  44.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  45.  
  46.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  47.                                      &flFrameFlags, szClientClass,
  48.                                      NULL, 0L, NULL, NULL, &hwndClient) ;
  49.  
  50.      WinSetWindowPos (hwndFrame, HWND_TOP, 0, 0,
  51.              WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN)/3,   // cx
  52.              WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR),   // cy
  53.              SWP_SHOW | SWP_SIZE | SWP_MOVE);
  54.  
  55.      tidTimer   = _beginthread (TimerThread,   iTimerThreadStack,   THREADSTACKSIZE, NULL) ;
  56.      tidCounter = _beginthread (CounterThread, iCounterThreadStack, THREADSTACKSIZE, NULL) ;
  57.  
  58.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  59.           WinDispatchMsg (hab, &qmsg) ;
  60.  
  61.      WinDestroyWindow (hwndFrame) ;
  62.      WinDestroyMsgQueue (hmq) ;
  63.      WinTerminate (hab) ;
  64.      return 0 ;
  65.      }
  66.  
  67. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  68.      {
  69.      switch (msg)
  70.           {
  71.           case WM_SEM1:
  72.                {
  73.                static char szBuffer [60];
  74.  
  75.                sprintf (szBuffer, "%ld counts/sec", LONGFROMMP (mp1));
  76.                WinSetWindowText (hwndFrame, szBuffer) ;
  77.                WinInvalidateRect (hwndFrame, NULL, FALSE);
  78.                WinUpdateWindow (hwndFrame);
  79.                return 0 ;
  80.                }
  81.  
  82.           case WM_DESTROY:
  83.                {
  84.                DosCloseSem (hSem);
  85.                return 0 ;
  86.                }
  87.           }
  88.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  89.      }
  90.  
  91. VOID TimerThread ()
  92.      {
  93.      DosSetPrty (PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, tidTimer);
  94.      while (TRUE)
  95.           {
  96.           DosSleep (1000L);
  97.  
  98.           WinPostMsg (hwndClient, WM_SEM1, MPFROMLONG (lCount), NULL) ;
  99.           lCount = 0L;
  100.           }
  101.      }
  102.  
  103. VOID CounterThread ()
  104.      {
  105.      DosSetPrty (PRTYS_THREAD, PRTYC_IDLETIME, 0, tidCounter);
  106.      while (TRUE) lCount++;
  107.      }
  108.